blob: 3580e6ae29119976b1d3c4f74702be2ad9691344 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
// import db from "../../lib/db";
import { NLP } from "sortug-ai";
type Req = { endpoint: "nlp" | "llm"; app: string; body: any };
export const POST = async (request: Request): Promise<Response> => {
const url = URL.parse(request.url);
const path = url!.pathname.replace("/api/formdata", "");
const body = await request.formData();
if (path === "/ocr") return postOCR(body);
// TODO audio etc. a lot of stuff goes through here
// if (!body.name || !body.creds) {
return Response.json({ message: "Invalid" }, { status: 400 });
// }
// try {
// const res = db.loginUser(body.name, body.creds);
// console.log({ res });
// return Response.json(res, { status: 200 });
// } catch (error) {
// return Response.json({ message: "Failure" }, { status: 500 });
// }
};
export const GET = async (request: Request): Promise<Response> => {
console.log({ request });
// if (!body.name || !body.creds) {
return Response.json({ message: "Invalid" }, { status: 400 });
// }
// try {
// const res = db.loginUser(body.name, body.creds);
// console.log({ res });
// return Response.json(res, { status: 200 });
// } catch (error) {
// return Response.json({ message: "Failure" }, { status: 500 });
// }
};
async function postOCR(formData: FormData) {
try {
const res = await NLP.ocr(formData);
console.log({ res });
return Response.json(res, { status: 200 });
} catch (error) {
return Response.json({ message: "Failure" }, { status: 500 });
}
}
|